package com.hsxc.cdz.monitor.bean.second;

import com.hsxc.cdz.base.util.BytesUtil;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.ReferenceCountUtil;

public class Fate {
	private int[] chargeFate; //费率  4字节  倍率系数0.00001 
	
	public static final int length = 48;
	public Fate(){
		chargeFate = new int[length];
	}
	
	public Fate(byte[] data){
		this();
		setFate(data);
	}
	
	public void setFate(byte[] data){
		if(data.length<length*4){
			return;
		}
        for(int i=0;i<length;i++){
			chargeFate[i] = BytesUtil.bytesToIntDesc(BytesUtil.getByte(i*4, 4, data));
		}
	}
	
	public byte[] getFate(){
		ByteBuf bytes = Unpooled.buffer(length*4);
		for(int i=0;i<length;i++){
			bytes.writeBytes(BytesUtil.intToBytesDesc(chargeFate[i], 4));
		}
		byte[] result = new byte[bytes.readableBytes()];
		bytes.readBytes(result);
		ReferenceCountUtil.release(bytes);
		return result;
	}
}
